1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| #include<iostream> #include<opencv2/opencv.hpp> #include"mydft.h" #include"Salt.h"
using namespace std; using namespace cv;
int main(){ Mat img,img_gray,img_out,img_transform; img = imread("/home/v/home.png"); if(img.empty()){ cout<<"can't open the image"<<endl; return -1; }
imshow("img",img); cvtColor(img,img_gray,COLOR_BGR2GRAY); imshow("img_gray",img_gray); Salt(img_gray,1000); imshow("img_gray_salt",img_gray);
mydft(img_gray,img_out,img_transform); imshow("img_out",img_out);
Mat planes[] = {Mat_<float>(img_out.size()),Mat::zeros(img_out.size(),CV_32F)}; split(img_transform,planes); Mat img_transform_real = planes[0]; Mat img_transform_imag = planes[1];
int core_x = img_transform_real.rows/2; int core_y = img_transform_real.cols/2; int r = 60; float h;
for (int i = 0; i < img_transform_real.rows; i++){ for (int j = 0; j < img_transform_real.cols; j++){ h = exp(-((i-core_x)*(i-core_x)+(j-core_y)*(j-core_y)/(2*r*r))); img_transform_real.at<float>(i,j) *= h; img_transform_imag.at<float>(i,j) *= h; } }
planes[0] = img_transform_real; planes[1] = img_transform_imag; Mat img_transform_ilpd; merge(planes,2,img_transform_ilpd);
Mat iDft[] = {Mat_<float>(img_out),Mat::zeros(img_out.size(),CV_32F)}; idft(img_transform_ilpd,img_transform_ilpd); split(img_transform_ilpd,iDft); magnitude(iDft[0],iDft[1],iDft[0]); normalize(iDft[0],iDft[0],0,1,NORM_MINMAX); imshow("idft",iDft[0]); waitKey(0); return 0; }
|